package com.example.springboot.service;

import com.example.springboot.controller.dto.UserDTO;
import com.example.springboot.entity.User;
import com.example.springboot.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public int save(User user) {
        if(user.getId() == null) {//user没有id，则表示新增
            return userMapper.insert(user);
        } else {//否则为更新
            return userMapper.update(user);
        }
    }

    public List<User> findAll() {
        List<User> all = userMapper.findall();
        return all;
    }

    public Integer delete(Integer id) {
        return userMapper.deleteById(id);
    }

    public List<User> login(UserDTO userDTO) {
        return userMapper.login(userDTO);
    }
}
